package com.wcs.exam.controller.admin;

import com.wcs.exam.common.base.Result;
import com.wcs.exam.common.base.annotation.OptLog;
import com.wcs.exam.common.base.annotation.OptLogCache;
import com.wcs.exam.common.base.page.Page;
import com.wcs.exam.controller.admin.biz.AdminMaterialBiz;
import com.wcs.exam.controller.admin.req.*;
import com.wcs.exam.controller.admin.resp.AdminMaterialPageResp;
import com.wcs.exam.controller.admin.resp.AdminMaterialPreviewResp;
import com.wcs.exam.controller.admin.resp.AdminMaterialViewResp;
import com.wcs.exam.controller.admin.resp.AdminMaterialVodUploadResp;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Admin-素材信息
 *
 * @author wcs
 * @since 2025-03-24
 */
@Tag(name = "Admin-素材信息")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/admin/material")
public class AdminMaterialController {

    @NotNull
    private final AdminMaterialBiz biz;

    @Operation(summary = "素材信息-分页")
    @OptLog(value = "素材信息-分页")
    @GetMapping(value = "/page")
    public Result<Page<AdminMaterialPageResp>> page(@ModelAttribute AdminMaterialPageReq req) {
        return biz.page(req);
    }

    @Operation(summary = "素材信息-添加")
    @OptLogCache
    @PostMapping(value = "/save")
    public Result<String> save(@RequestBody @Valid AdminMaterialSaveReq req) {
        return biz.save(req);
    }

    @Operation(summary = "素材信息-查看")
    @Parameter(name = "id", description = "主键ID", required = true)
    @GetMapping(value = "/view")
    public Result<AdminMaterialViewResp> view(@RequestParam Long id) {
        return biz.view(id);
    }

    @Operation(summary = "素材信息-编辑")
    @OptLog(value = "素材信息编辑", isUpdate = true)
    @PutMapping(value = "/edit")
    public Result<String> edit(@RequestBody @Valid AdminMaterialEditReq req) {
        return biz.edit(req);
    }

    @Operation(summary = "素材信息-更新状态")
    @OptLog(value = "素材信息更新状态")
    @PutMapping(value = "/update/status")
    public Result<String> updateStatus(@RequestBody @Valid AdminMaterialUpdateStatusReq req) {
        return biz.updateStatus(req);
    }

    @Operation(summary = "素材信息-排序")
    @OptLog(value = "素材信息排序")
    @PutMapping(value = "/sort")
    public Result<String> sort(@RequestBody @Valid List<AdminMaterialSortReq> reqs) {
        return biz.sort(reqs);
    }

    @Operation(summary = "素材信息-删除")
    @Parameter(name = "id", description = "主键ID", required = true)
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam Long id) {
        return biz.delete(id);
    }

    @Operation(summary = "素材信息-批量移动")
    @OptLog(value = "素材信息-批量移动")
    @PutMapping(value = "/batch/edit")
    public Result<String> batchEdit(@RequestBody @Valid AdminMaterialBatchEditReq req) {
        return biz.batchEdit(req);
    }

    @Operation(summary = "素材信息-批量删除")
    @OptLog(value = "素材信息-批量删除")
    @DeleteMapping(value = "/batch/delete")
    public Result<String> batchDelete(@RequestBody @Valid AdminMaterialBatchDeleteReq req) {
        return biz.batchDelete(req);
    }

    @Operation(summary = "获取音视频上传参数")
    @OptLog(value = "素材信息-音视频上传")
    @GetMapping(value = "/vod/upload")
    public Result<AdminMaterialVodUploadResp> vodUpload() {
        return biz.vodUpload();
    }


    @Operation(summary = "获取预览参数")
    @OptLog(value = "素材信息-预览")
    @GetMapping(value = "/preview")
    public Result<AdminMaterialPreviewResp> preview(@RequestParam Long id) {
        return biz.preview(id);
    }
}
